package org.wattdepot.cli;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * Tests the UserCommandInterface package.
 * 
 * @author Jarret Mizo, Shaun Ramento
 * 
 */
public class TestUserCommandInterface {

  /**
   * Tests the sourceExist method.
   * 
   * @throws Exception if there is a problem.
   */
  @Test
  public void testSourceExists() throws Exception {
    UserCommandInterface user = new UserCommandInterface();
    assertTrue("Checking vaild input", user.sourceExists("SIM_KAHE"));
    assertFalse("Check invalid input", user.sourceExists("RandomSource"));
  }

  /**
   * Tests returning the help in the getInputKeywords() method.
   * 
   * @throws Exception if there is a problem.
   */
  @Test
  public void testHelp() throws Exception {
    UserCommandInterface user = new UserCommandInterface();
    String input = "help";
    String returnedInput = user.getInputKeywords(input);
    assertTrue("Checking good help", returnedInput.equalsIgnoreCase(input));
    input = "help extraword";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad help", returnedInput);
  }

  /**
   * Tests returning the quit in the getInputKeywords() method.
   * 
   * @throws Exception if there is a problem.
   */
  @Test
  public void testQuit() throws Exception {
    UserCommandInterface user = new UserCommandInterface();
    String input = "quit";
    String returnedInput = user.getInputKeywords(input);
    assertTrue("Checking good quit", returnedInput.equalsIgnoreCase(input));
    input = "quit extraword";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad quit", returnedInput);
  }

  /**
   * Tests returning the sources in the getInputKeywords() method.
   * 
   * @throws Exception if there is a problem.
   */
  @Test
  public void testSources() throws Exception {
    UserCommandInterface user = new UserCommandInterface();
    String input = "sources";
    String returnedInput = user.getInputKeywords(input);
    assertTrue("Checking good sources", returnedInput.equalsIgnoreCase(input));
    input = "sources extraword";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad sources", returnedInput);
  }

  /**
   * Tests returning the summary in the getInputKeywords() method.
   * 
   * @throws Exception if there is a problem.
   */
  @Test
  public void testSummary() throws Exception {
    UserCommandInterface user = new UserCommandInterface();
    String input = "summary {source}";
    String returnedInput = user.getInputKeywords(input);
    assertTrue("Checking good summary", returnedInput.equalsIgnoreCase("summary"));
    input = "summary {source} extraword";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad summary", returnedInput);
  }

  /**
   * Tests returning the 2.5 keyword in the getInputKeywords() method.
   * 
   * @throws Exception if there is a problem.
   */
  @Test
  public void testSensorTimestamp() throws Exception {
    UserCommandInterface user = new UserCommandInterface();
    String input = "sensordata {source} timestamp {timestamp}";
    String returnedInput = user.getInputKeywords(input);
    assertTrue("Checking good sources", returnedInput.equalsIgnoreCase("sensordatatimestamp"));
    input = "sensordata {source} timestamp {timestamp} extraword";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad sources", returnedInput);
    input = "sensordata {source} timestamp";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad sensordata timestamp", returnedInput);
  }

  /**
   * Tests returning the 2.6 keyword in the getInputKeywords() method.
   * 
   * @throws Exception if there is a problem.
   */
  @Test
  public void testSensorDay() throws Exception {
    UserCommandInterface user = new UserCommandInterface();
    String input = "dailysensordata {source} day {day}";
    String returnedInput = user.getInputKeywords(input);
    assertTrue("Checking good dailysensordata", returnedInput
        .equalsIgnoreCase("dailysensordataday"));
    input = "dailysensordata {source} day {day} extraword";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad Sensorday", returnedInput);
    input = "dailysensordata {source} dailysensordata";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad sensorday", returnedInput);
  }

  /**
   * Tests returning the 2.7 keyword in the getInputKeywords() method.
   * 
   * @throws Exception if there is a problem.
   */
  @Test
  public void testPowerTimestamp() throws Exception {
    UserCommandInterface user = new UserCommandInterface();
    String input = "power [generated|consumed] {source} timestamp {timestamp}";
    String returnedInput = user.getInputKeywords(input);
    assertTrue("Checking good power timestamp", returnedInput.equalsIgnoreCase("powertimestamp"));
    input = "power [generated|consumed] {source} timestamp {timestamp} extra";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking extra dailysensordata", returnedInput);
    input = "power [generated|consumed] {source} timestamp";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking short dailysensordata", returnedInput);
  }

  /**
   * Tests returning the 2.8 keyword in the getInputKeywords() method.
   * 
   * @throws Exception if there is a problem.
   */
  @Test
  public void testPowerstatsDay() throws Exception {
    UserCommandInterface user = new UserCommandInterface();
    String input =
        "powerstats [generated|consumed] {source} day {day} sampling-interval {minutes} "
            + "statistic {max|min|average}";
    String returnedInput = user.getInputKeywords(input);
    assertTrue("Checking good power timestamp", returnedInput
        .equalsIgnoreCase("powerstatsdaysampling-intervalstatistic"));
    input =
        "powerstats [generated|consumed] {source} day {day} sampling-interval {minutes} "
            + "statistic {max|min|average} extra";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad dailysensordata", returnedInput);
    input =
        "powerstats [generated|consumed] {source} day {day} sampling-interval {minutes} statistic";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad dailysensordata", returnedInput);
  }

  /**
   * Tests returning the 2.9 keyword in the getInputKeywords() method.
   * 
   * @throws Exception if there is a problem.
   */
  @Test
  public void testTotalGenerated() throws Exception {
    UserCommandInterface user = new UserCommandInterface();
    String input =
        "total [carbon|energy] generated {source} day {day} " + "sampling-interval {minutes}";
    String returnedInput = user.getInputKeywords(input);
    assertTrue("Checking good total generated", returnedInput
        .equalsIgnoreCase("totalgenerateddaysampling-interval"));
    input = "total [carbon|energy] generated {source} day {day} sampling-interval {minutes} extra";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad total generated", returnedInput);
    input = "total [carbon|energy] generated {source} day {day} sampling-interval";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad total generated", returnedInput);
  }

  /**
   * Tests returning the 2.10 keyword in the getInputKeywords() method.
   * 
   * @throws Exception if there is a problem.
   */
  @Test
  public void testChart() throws Exception {
    UserCommandInterface user = new UserCommandInterface();
    String input =
        "chart power [generated|consumed] {source} {startday} {endday} "
            + "sampling-interval {minutes} file {file}";
    String returnedInput = user.getInputKeywords(input);
    assertTrue("Checking good total generated", returnedInput
        .equalsIgnoreCase("chartpowersampling-intervalfile"));
    input =
        "chart power [generated|consumed] {source} {startday} {endday} "
            + "sampling-interval {minutes} file {file} extra";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad chart", returnedInput);
    input =
        "chart power [generated|consumed] {source} {startday} {endday} "
            + "sampling-interval {minutes} file";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad chart", returnedInput);
  }

  /**
   * Tests returning the 2.11 keyword in the getInputKeywords() method.
   * 
   * @throws Exception if there is a problem.
   */
  @Test
  public void testFuelTypes() throws Exception {
    UserCommandInterface user = new UserCommandInterface();
    String input = "fueltypes {source}";
    String returnedInput = user.getInputKeywords(input);
    assertTrue("Checking good fueltype", returnedInput.equalsIgnoreCase("fueltypes"));
    input = "fueltypes {source} something";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking long command", returnedInput);
    input = "fueltypes";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking short command", returnedInput);
  }

  /**
   * Tests returning the 2.12 keyword in the getInputKeywords() method.
   * 
   * @throws Exception if there is a problem.
   */
  @Test
  public void testTotalPowerFuelTypes() throws Exception {
    UserCommandInterface user = new UserCommandInterface();
    String input = "totalpower {source} {timestamp} fuelType {fueltype}";
    String returnedInput = user.getInputKeywords(input);
    assertTrue("Checking good total fuel type", returnedInput
        .equalsIgnoreCase("totalpowerfueltype"));
    input = "totalpower {source} {timestamp} fuelType {fueltype} something";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad total fuel type", returnedInput);
    input = "totalpower {source} {timestamp}";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad total fuel type", returnedInput);
  }

  /**
   * Tests returning the 2.13 keyword in the getInputKeywords() method.
   * 
   * @throws Exception if there is a problem.
   */
  @Test
  public void testCarbonCont() throws Exception {
    UserCommandInterface user = new UserCommandInterface();
    String input = "carboncontent {source} {timestamp} sampling-interval {interval}";
    String returnedInput = user.getInputKeywords(input);
    assertTrue("Checking good carboncontent", returnedInput
        .equalsIgnoreCase("carboncontentsampling-interval"));
    input = "carboncontent {source} {timestamp} sampling-interval {interval} extra";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad carbon content", returnedInput);
    input = "carboncontent {source} {timestamp} sampling-";
    returnedInput = user.getInputKeywords(input);
    assertNull("Checking bad carboncontent", returnedInput);
  }
}
